<?php include 'header.php'; ?>
            <h2>个人中心</h2>
            <h3>我的帖子</h3>
            <?php
            include 'db_connect.php';
	    
            $username = $_SESSION['username'];
            $sql = "SELECT * FROM posts WHERE author = '$username' ORDER BY created_at DESC";
            $result = $conn->query($sql);

            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo '<article class="post">';
                    echo '<h2><a href="post.php?id=' . $row["id"] . '">' . $row["title"] . '</a></h2>';
                    echo '<div class="post-meta">发布时间: ' . $row["created_at"] . '</div>';
                    echo '<p>' . substr($row["content"], 0, 200) . '...</p>';
                    echo '<a href="post.php?id=' . $row["id"] . '" class="btn">查看</a>';
                    echo '</article>';
                }
            } else {
                echo '<p>您还没有发布任何帖子！</p>';
            }
            $conn->close();
            ?>
<?php include 'footer.php'; ?>
